<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
use think\Session;
class Index extends Controller
{
    //管理员登录页
    public function index()
    {
        return $this->fetch();
    }
    //处理登录
    public function login()
    {
        $data = [
            "admin_phone"=>input('phone'),
            "admin_pw"=>md5(input('pw')),
        ];
        $data1 = [
            "hos_phone"=>input('phone'),
            "hos_pw"=>md5(input('pw')),
        ];
        $id = input('id');
        if($id == 1){
            $res = Db::name('admin')->where($data)->find();
            // dump($res);
            // exit;
            if($res==null){
                return $this->error('账号密码错误');
            }else{
                Session::set("admin_id",$res["admin_id"]);
                $this->success('登录成功','home/index');
            }
        }
        else{
            $res = Db::name('hos')->where($data1)->find();
            // dump($res);
            // exit;
            $res1 = Db::name('hospital')->where('hospital_id',$res['hospital_id'])->find();
            // dump($res1);
            // exit;
            if($res==null){
                return $this->error('账号密码错误');
            }else{
                Session::set("hos_id",$res["hos_id"]);
                Session::set("hospital_name",$res1["hospital_name"]);
                Session::set("hospital_id",$res1["hospital_id"]);
                $this->success('登录成功','adminhos/index');
            }
        }
        
    }
    //注销功能
    public function logout(){
		Session::clear();
    	$this->redirect("index/index");
    }
}
